<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>租车登录页面</title>
    <link rel="stylesheet" href="/car_rental/u/css/login.css">
    <link rel="stylesheet" href="/car_rental/u/css/register.css">
    <script src="/car_rental/u/js/jquery-3.7.1.min.js"></script>
    <style>
    </style>
</head>
<body>
<div class="container">
    <h2>登录租车账户</h2>
    <form action="#" method="post">
        <input id="username" type="text" name="username" placeholder="用户名" required>
        <input id="password" type="password" name="password" placeholder="密码" required>
        <div class="captcha-container">
            <input id="code" type="text" class="captcha-input" name="captcha" placeholder="验证码" required>
            <img class="captcha-image" src="https://via.placeholder.com/120x40.png?text=CAPTCHA" alt="验证码">
        </div>
        <input class="button" type="button" value="登录">
    </form>
    <div class="footer">
        没有账号？ <a href="register.jsp">立即注册</a>
    </div>
</div>
</body>
<script>
    $(function () {
        $(".button").click(function () {
            $.get('/car_rental/loginServlet', {
                'username': $("#username").val(),
                'password': $("#password").val()
            }, function (data) {
                if (data.meg == '成功') {
                    if (data.user.authority == 1) {//管理员
                        console.log('管理员');
                    } else {
                        console.log('用户');
                        window.location.href = '/car_rental/u/index.jsp';
                    }
                } else {
                    console.log('失败');
                }
            });
        });
    });

</script>

</html>